
/*

DEPENDENCIES:
-------------
Gimme.Effects
ext.get_style_pos
-------------


IN THIS FILE:
-------------
ext.slide
-------------

*/

Gimme.ext.slide = function(fromPt, toPt, duration, guid, callback, easing)
{
	function getPos(elem, axis)
	{
		axis = axis === 'left' ? 'x' : 'y';
		
		var p = elem.__pos;
		if (!p)
		{
			p = elem.__pos = Gimme(elem).get_style_pos();
		}
		
		if (axis === 'y')
		{
			elem.__pos = Gimme.undefined;
		}
		
		return p[axis];
	}
	
	if (fromPt === null)
	{
		fromPt = { x: getPos, y: getPos };
	}

	var round = Math.round;
	var ease = Gimme.Effects.Easing.Exponential.ease_in_out;
	
	var sb = Gimme.Effects.Storyboard.create
	(
		// items to animate
		this,
		
		// from
		{
			left: fromPt.x,
			top: fromPt.y
		},
		
		//to
		{
			left: toPt.x,
			top: toPt.y
		},				
		
		//animate function
		function(elem, props)
		{
			elem.style.top = round(props.top) + 'px';
			elem.style.left = round(props.left) + 'px';
		},
		
		//durations
		duration,
		
		//guid
		guid,
		
		//callback
		callback,
		
		//easing
		easing || function(t)
		{
			return ease(t, 4);
		}
	);
	
	sb.begin();
	return this;
};